package com.crm.base;


import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 业务层公共实现类
 */
public class BaseServiceImpl<M extends BaseMapper<T>, T> implements BaseService<T> {

    @Autowired
    protected M baseMapper;  // 同一包的类和子类可以访问

    @Override
    public Boolean add(T t) {
        return baseMapper.insert(t) > 0;
    }

    @Override
    public Boolean batchAdd(List<T> list) {
        return baseMapper.insertBatch(list) > 0;
    }

    @Override
    public Boolean del(Integer id) {
        return baseMapper.delete(id) > 0;
    }

    @Override
    public Boolean batchDel(String[] ids) {
        return baseMapper.deleteBatch(ids) > 0;
    }

    @Override
    public Boolean upd(T t) {
        return baseMapper.update(t) > 0;
    }

    @Override
    public Boolean batchUpd(List<T> list) {
        return baseMapper.updateBatch(list) > 0;
    }

    @Override
    public T findById(Integer id) {
        return baseMapper.selectById(id);
    }

    @Override
    public List<T> findAll(T t) {
        return baseMapper.select(t);
    }
}
